package util.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wq.cycling.R;

import java.util.ArrayList;

import bean.EntityForSimple;

/**
 * sosAdapter
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */

public class MessageAdapter extends BaseAdapter {

	private Activity mContext;
	private LayoutInflater mInflater;
	public ArrayList<EntityForSimple> mDatas;
	public MessageAdapter(Activity context, ArrayList<EntityForSimple> mDatas) {
		mContext = context;
		this.mDatas = mDatas;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mDatas.size();
	}

	@Override
	public Object getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listview_message_item,null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_title.setText(mDatas.get(position).getDevicename());
		holder.tv_content.setText(getType(mDatas.get(position).getAlarmType()));
		holder.tv_time.setText(mDatas.get(position).getAlarmTime());

		return convertView;
	}

	private static class ViewHolder {
		public TextView tv_title,tv_content,tv_time;
		ViewHolder(View view) {
			tv_title = ((TextView) view.findViewById(R.id.tv_title));
			tv_content = ((TextView) view.findViewById(R.id.tv_content));
			tv_time = ((TextView) view.findViewById(R.id.tv_time));
		}
	}

	public static interface MyItemTop{
		void listener(int item);
	}

	private MyItemTop top;

	public void setTopListener(MyItemTop top){
		this.top = top;
	}

	public String getType(String type) {
		try {
			int mtype = Integer.valueOf(type);
			String content = mContext.getResources().getString(R.string.switch1);
			switch (mtype) {
				case 1:
					content = mContext.getResources().getString(R.string.switch1);
					break;
				case 2:
					content = mContext.getResources().getString(R.string.switch2);
					break;
				case 3:
					content = mContext.getResources().getString(R.string.switch3);
					break;
				case 4:
					content = mContext.getResources().getString(R.string.switch4);
					break;
				case 5:
					content = mContext.getResources().getString(R.string.switch5);
					break;
				case 6:
					content = mContext.getResources().getString(R.string.switch6);
					break;
				case 7:
					content = mContext.getResources().getString(R.string.switch7);
					break;
				case 8:
					content = mContext.getResources().getString(R.string.switch8);
					break;
				case 9:
					content = mContext.getResources().getString(R.string.switch9);
					break;

			}
			return content;
		} catch (Exception e) {
			return mContext.getResources().getString(R.string.switch1);
		}
	}
}
